﻿using System;
using System.Collections.Generic;
using System.Data;

namespace SBPweb.DNN.PhotoGallery
{
    /// <summary>
    /// Summary description for PhotoGallerySlideController
    /// </summary>
    public class PhotoGallerySlideController
    {
        static public List<PhotoGallerySlideInfo> GetPhotoGallerySlides(int PhotoGalleryId)
        {
            List<PhotoGallerySlideInfo> PhotoGallerySlidesInfolist = new List<PhotoGallerySlideInfo>();
            using (IDataReader dr = DataProvider.Instance().GetPhotoGallerySlides(PhotoGalleryId))
            {
                while (dr.Read())
                {
                    PhotoGallerySlideInfo photoGallerySlideInfo = new PhotoGallerySlideInfo(string.Empty, string.Empty);
                    photoGallerySlideInfo.PhotoGalleryId = Convert.ToInt32(dr["PhotoGalleryId"]);
                    photoGallerySlideInfo.PhotoGallerySlideId = Convert.ToInt32(dr["PhotoGallerySlideId"]);
                    photoGallerySlideInfo.Caption = Convert.ToString(dr["Caption"]);
                    photoGallerySlideInfo.Image = new Uri(Convert.ToString(dr["Image"]), UriKind.RelativeOrAbsolute);
                    photoGallerySlideInfo.OrderIndex = Convert.ToInt32(dr["OrderIndex"]);
                    if (!(dr["Thumb"] is DBNull))
                    {
                        photoGallerySlideInfo.Thumbnail = new Uri(Convert.ToString(dr["Thumb"]), UriKind.RelativeOrAbsolute);
                    }
                    if (!(dr["AnimationBegin"] is DBNull))
                    {
                        photoGallerySlideInfo.AnimationBegin = Convert.ToInt32(dr["AnimationBegin"]);
                    }
                    if (!(dr["AnimationEnd"] is DBNull))
                    {
                        photoGallerySlideInfo.AnimationEnd = Convert.ToInt32(dr["AnimationEnd"]);
                    }
                    if (!(dr["BorderColor"] is DBNull))
                    {
                        photoGallerySlideInfo.BorderColor = Convert.ToString(dr["BorderColor"]);
                    }
                    if (!(dr["BorderRadius"] is DBNull))
                    {
                        photoGallerySlideInfo.BorderRadius = Convert.ToInt32(dr["BorderRadius"]);
                    }
                    if (!(dr["BorderVisible"] is DBNull))
                    {
                        photoGallerySlideInfo.BorderVisible = Convert.ToBoolean(dr["BorderVisible"]);
                    }
                    if (!(dr["BorderWidth"] is DBNull))
                    {
                        photoGallerySlideInfo.BorderWidth = Convert.ToInt32(dr["BorderWidth"]);
                    }
                    if (!(dr["CenterX"] is DBNull))
                    {
                        photoGallerySlideInfo.CenterX = Convert.ToDouble(dr["CenterX"]);
                    }
                    if (!(dr["CenterY"] is DBNull))
                    {
                        photoGallerySlideInfo.CenterY = Convert.ToDouble(dr["CenterY"]);
                    }
                    if (!(dr["Duration"] is DBNull))
                    {
                        photoGallerySlideInfo.Duration = Convert.ToInt32(dr["Duration"]);
                    }
                    if (!(dr["EndDelay"] is DBNull))
                    {
                        photoGallerySlideInfo.EndDelay = Convert.ToInt32(dr["EndDelay"]);
                    }
                    if (!(dr["RotateAngle"] is DBNull))
                    {
                        photoGallerySlideInfo.RotateAngle = Convert.ToDouble(dr["RotateAngle"]);
                    }
                    if (!(dr["Scale"] is DBNull))
                    {
                        photoGallerySlideInfo.Scale = Convert.ToDouble(dr["Scale"]);
                    }
                    PhotoGallerySlidesInfolist.Add(photoGallerySlideInfo);
                }
            }
            PhotoGallerySlidesInfolist.Sort();
            return PhotoGallerySlidesInfolist;
        }

        public static void DeletePhotoGallerySlide(PhotoGallerySlideInfo slideInfo)
        {
            DataProvider.Instance().DeletePhotoGallerySlide(slideInfo.PhotoGallerySlideId);
        }

        public static int AddPhotoGallerySlide(PhotoGallerySlideInfo slideInfo)
        {
            return ((int)(DataProvider.Instance().AddPhotoGallerySlide(
                slideInfo.PhotoGalleryId,
                slideInfo.Caption,
                slideInfo.Image.OriginalString,
                slideInfo.Thumbnail.OriginalString,
                slideInfo.OrderIndex,
                slideInfo.Scale,
                slideInfo.CenterX,
                slideInfo.CenterY,
                slideInfo.AnimationBegin,
                slideInfo.AnimationEnd,
                slideInfo.BorderColor,
                slideInfo.BorderRadius,
                slideInfo.BorderVisible,
                slideInfo.BorderWidth,
                slideInfo.Duration,
                slideInfo.EndDelay,
                slideInfo.RotateAngle)));
        }

        public static void UpdatePhotoGallerySlide(PhotoGallerySlideInfo slideInfo)
        {
            DataProvider.Instance().UpdatePhotoGallerySlide(
                slideInfo.PhotoGallerySlideId,
                slideInfo.PhotoGalleryId,
                slideInfo.Caption,
                slideInfo.Image.OriginalString,
                slideInfo.Thumbnail.OriginalString,
                slideInfo.OrderIndex,
                slideInfo.Scale,
                slideInfo.CenterX,
                slideInfo.CenterY,
                slideInfo.AnimationBegin,
                slideInfo.AnimationEnd,
                slideInfo.BorderColor,
                slideInfo.BorderRadius, 
                slideInfo.BorderVisible,
                slideInfo.BorderWidth,
                slideInfo.Duration,
                slideInfo.EndDelay,
                slideInfo.RotateAngle);
        }
        /*
        public static void AddSurveyResult(PhotoGallerySlideInfo objPhotoGallerySlideInfo, int UserID)
        {
            //DataProvider.Instance().AddSurveyResult(objPhotoGalleryOption.SurveyOptionId, UserID);
        }
        */
    }
}